package com.bbtShop.api;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.bbtShop.aop.Login;
import com.bbtShop.core.model.*;
import com.bbtShop.service.ProductRecodeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author manke
 * @Date 2020/10/13 16:50
 * @Version 0.0.1
 */
@Api(value = "ProductRecodeController", description = "产品记录控制器")
@RestController
@RequestMapping("/ProductRecode")
public class ProductRecodeController {
    @Autowired
    private ProductRecodeService productRecodeService;

    @ApiOperation(value = "getLisProductRecode", notes = "获取产品记录列表")
    @PostMapping("/getLisProductRecode")
    @Login(permission = "ProductRecode:getLisProductRecode")
    public ApiResponse<Object> getLisProductRecode(@RequestParam(required = false) Integer pageNum,
                                                   @RequestParam(required = false) Integer pageSize, @RequestBody ProductRecode productRecode) {
        return ApiResponse.success(productRecodeService.getLisProductRecode(pageNum, pageSize, productRecode));
    }

    @ApiOperation(value = "addUpdateProductRecode", notes = "添加修改产品记录")
    @PostMapping("/addUpdateProductRecode")
    @Login(permission = "ProductRecode:addUpdateProductRecode")
    public ApiResponse<Object> addUpdateProductRecode(@RequestBody ProductRecode productRecode) {
        productRecodeService.addUpdateProductRecode(productRecode);
        return ApiResponse.success();
    }

    @ApiOperation(value = "delProductRecode", notes = "删除产品记录")
    @PostMapping("/delProductRecode")
    @Login(permission = "ProductRecode:delProductRecode")
    public ApiResponse<Object> delProductRecode(@RequestBody Ids ids) {
        productRecodeService.delProductRecode(ids);
        return ApiResponse.success();
    }

    @ApiOperation(value = "delProductRecodeByTime", notes = "删除产品记录根据时间")
    @PostMapping("/delProductRecodeByTime")
    @Login(permission = "ProductRecode:delProductRecodeByTime")
    public ApiResponse<Object> delProductRecodeByTime(@RequestBody DatesVo datesVo) {
        productRecodeService.delProductRecodeByTime(datesVo);
        return ApiResponse.success();
    }

    @ApiOperation(value = "getProductRecodeInfo", notes = "获取产品记录详情信息")
    @GetMapping("/getProductRecodeInfo")
    @Login(permission = "ProductRecode:getProductRecodeInfo")
    public ApiResponse<ProductRecode> getProductRecodeInfo(@RequestParam Integer id) {
        return ApiResponse.success(productRecodeService.getProductRecodeInfo(id));
    }

    @ApiOperation(value = "getProductSalesByTime", notes = "按照时间区间获取当天销量")
    @PostMapping("/getProductSalesByTime")
    @Login(permission = "ProductRecode:getProductSalesByTime")
    public ApiResponse<IPage<ProduceRecodeDayView>> getProductSalesByTime(@RequestBody ProduceViewTimeVo produceViewTimeVo, @RequestParam Integer pageNum, @RequestParam Integer pageSize) {
        IPage<ProduceRecodeDayView> list = productRecodeService.getProductSalesByTime(produceViewTimeVo, pageNum, pageSize);
        return ApiResponse.success(list);
    }

}
